/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nuevoingresoA;

import conexion.Conexion;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author PACHITO
 */
@WebServlet(name = "totalapagar", urlPatterns = {"/totalapagar"})
public class totalapagar extends HttpServlet {

    Conexion conecta = new Conexion();
    Statement sentenciaSQL = null;
    ResultSet consulta = null;

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        conecta.Conectar();
        sentenciaSQL = conecta.getSentenciaSQL();
    }

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet totalapagar</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet totalapagar at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String nivell = request.getParameter("nivel");
        String nom = request.getParameter("nom");
        String app = request.getParameter("app");
        String apm = request.getParameter("apm");
        try {
            consulta = sentenciaSQL.executeQuery("select inscripcion, mensualidad, "
                    + "enfermeria, incorporacion, uniforme, credencial, libros from "
                    + "cantidad where idnivel =" + nivell);
            int total = 0;
            out.println("<table>");
            while (consulta.next()) {
                total = consulta.getInt(1) + consulta.getInt(2) + consulta.getInt(3) + consulta.getInt(4)
                        + consulta.getInt(5) + consulta.getInt(6) + consulta.getInt(7);
                out.println(
                        "                                <tr>\n"
                        + "                                    <td><div id=\"tabladepagos\"></div></td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td >\n"
                        + "                                        nombre:\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input size=\"15\" type=\"fitextle\" name=\"nombrepago\" value=\"" + nom + "\" disabled=\"disabled\"/>\n"
                        + "                                    </td>\n"
                        + "\n"
                        + "\n"
                        + "                                    <td>\n"
                        + "                                        apellido paterno:\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input size=\"15\" type=\"text\" name=\"nombrepago\" value=\"" + app + "\" disabled=\"disabled\"/>\n"
                        + "                                    </td>\n"
                        + "\n"
                        + "\n"
                        + "                                    <td>\n"
                        + "                                        apellido materno:\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input size=\"15\" type=\"text\" name=\"nombrepago\" value=\"" + apm + "\" disabled=\"disabled\"/>\n"
                        + "                                    </td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td>\n"
                        + "                                        inscripcion:$\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input type=\"text\" name=\"nombrepago\" value=\"" + consulta.getInt(1) + "\" />\n"
                        + "                                    </td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td>\n"
                        + "                                        mensualidad:$\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input type=\"text\" name=\"nombrepago\" value=\"" + consulta.getInt(2) + "\" />\n"
                        + "                                    </td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td>\n"
                        + "                                        enfermeria:$\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input type=\"text\" name=\"nombrepago\" value=\"" + consulta.getInt(3) + "\" />\n"
                        + "                                    </td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td>\n"
                        + "                                        incorporacion:$\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input type=\"text\" name=\"nombrepago\" value=\"" + consulta.getInt(4) + "\" />\n"
                        + "                                    </td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td>\n"
                        + "                                        uniforme:$\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input type=\"text\" name=\"nombrepago\" value=\"" + consulta.getInt(5) + "\" />\n"
                        + "                                    </td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td>\n"
                        + "                                        credencial:$\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input type=\"text\" name=\"nombrepago\" value=\"" + consulta.getInt(6) + "\" />\n"
                        + "                                    </td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td>\n"
                        + "                                        libros:$\n"
                        + "                                    </td>\n"
                        + "                                    <td>\n"
                        + "                                        <input type=\"text\" name=\"nombrepago\" value=\"" + consulta.getInt(7) + "\" />\n"
                        + "                                    </td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td>Observaciones:</td>\n"
                        + "                                    <td colspan=\"3\"><textarea name=\"observaciones\" rows=\"4\" cols=\"20\">\n"
                        + "escribe alguna observacion\n"
                        + "                                        </textarea></td>\n"
                        + "                                </tr>\n"
                        + "                                <tr>\n"
                        + "                                    <td></td>\n"
                        + "                                    <td><input type=\"submit\" value=\"realizar pago\" /></td>\n"
                        + "                                </tr>\n"
                        + "                                \n");

            }
            out.println("</table>");
            out.println(total);

            out.close();



        } catch (SQLException e) {
            out.println("Excepcion sql111111" + e);
            out.println("" + sentenciaSQL);

        } catch (NullPointerException e) {
            out.println("Apuntando sql hector" + e + sentenciaSQL);
            out.println("" + sentenciaSQL);

        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
//        response.setContentType("text/html;charset=UTF-8");
//        PrintWriter out = response.getWriter();
//        String nivell = request.getParameter("nivel");
//        String nom = request.getParameter("nom");
//        String app = request.getParameter("app");
//        String apm = request.getParameter("apm");
//        try {
//            consulta = sentenciaSQL.executeQuery("select inscripcion, mensualidad, "
//                    + "enfermeria, incorporacion, uniforme, credencial, libros from "
//                    + "cantidad where idnivel =" + nivell);
//            int total = 0;
//
//            while (consulta.next()) {
//                total = consulta.getInt(1) + consulta.getInt(2) + consulta.getInt(3) + consulta.getInt(4)
//                        + consulta.getInt(5) + consulta.getInt(6) + consulta.getInt(7);
////                out.println("<table style=\"text-align: right\">\n" +
////"                                <tr>\n" +
////"                                    <td><div id=\"tabladepagos\"></div></td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td >\n" +
////"                                        nombre:\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input size=\"15\" type=\"fitextle\" name=\"nombrepago\" value=\"\" disabled=\"disabled\"/>\n" +
////"                                    </td>\n" +
////"\n" +
////"\n" +
////"                                    <td>\n" +
////"                                        apellido paterno:\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input size=\"15\" type=\"text\" name=\"nombrepago\" value=\"\" disabled=\"disabled\"/>\n" +
////"                                    </td>\n" +
////"\n" +
////"\n" +
////"                                    <td>\n" +
////"                                        apellido materno:\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input size=\"15\" type=\"text\" name=\"nombrepago\" value=\"\" disabled=\"disabled\"/>\n" +
////"                                    </td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td>\n" +
////"                                        inscripcion:$\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input type=\"text\" name=\"nombrepago\" value=\"\" />\n" +
////"                                    </td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td>\n" +
////"                                        mensualidad:$\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input type=\"text\" name=\"nombrepago\" value=\"\" />\n" +
////"                                    </td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td>\n" +
////"                                        enfermeria:$\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input type=\"text\" name=\"nombrepago\" value=\"\" />\n" +
////"                                    </td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td>\n" +
////"                                        incorporacion:$\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input type=\"text\" name=\"nombrepago\" value=\"\" />\n" +
////"                                    </td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td>\n" +
////"                                        uniforme:$\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input type=\"text\" name=\"nombrepago\" value=\"\" />\n" +
////"                                    </td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td>\n" +
////"                                        credencial:$\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input type=\"text\" name=\"nombrepago\" value=\"\" />\n" +
////"                                    </td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td>\n" +
////"                                        libros:$\n" +
////"                                    </td>\n" +
////"                                    <td>\n" +
////"                                        <input type=\"text\" name=\"nombrepago\" value=\"\" />\n" +
////"                                    </td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td>Observaciones:</td>\n" +
////"                                    <td colspan=\"3\"><textarea name=\"observaciones\" rows=\"4\" cols=\"20\">\n" +
////"escribe alguna observacion\n" +
////"                                        </textarea></td>\n" +
////"                                </tr>\n" +
////"                                <tr>\n" +
////"                                    <td></td>\n" +
////"                                    <td><input type=\"submit\" value=\"realizar pago\" /></td>\n" +
////"                                </tr>\n" +
////"                                \n" +
////"                            </table>");
//
//            }
//            
//            out.println(total);
//
//            out.close();
//
//
//
//        } catch (SQLException e) {
//            out.println("Excepcion sql111111" + e);
//            out.println("" + sentenciaSQL);
//
//        } catch (NullPointerException e) {
//            out.println("Apuntando sql hector" + e + sentenciaSQL);
//            out.println("" + sentenciaSQL);
//
//        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
